<?php
namespace app\admin\controller;

use app\common\model\ActionPopup as ActionPopupModel;

/**
 * 活动弹窗控制器
 * Class Action
 * @package app\index\controller
 */
class Actionpopup extends Base
{
    /**
     * [index  ]
     * @return mixed|string
     * @author [C。]
     */
    public function index()
    {
        $param = input('param.');
        $model = new ActionPopupModel;
        $this->getPageAndSize($param);
        $map = [];
        try {
            $count = $model->getCount($map);
            $allpage = intval(ceil($count / $this->size));//总页面
            $lists = $model->getlist($map, $this->from, $this->size);
        } catch (\Exception $e) {
            systembug($e->getMessage(),1,'admin/Actionpopup/index');
            return admin_json(-1, '获取失败' . $e->getMessage());
        }
        return admin_json(1, '获取成功', [
            'count' => $count,//总记录数
            'allpage' => $allpage,
            'lists' => $lists,
        ]);
    }
    /**
     * [index  ]
     * @return mixed|string
     * @author [C。]
     */
    public function add()
    {
        $param = input('param.');
        $model = new ActionPopupModel;
        try {
            $param['starttime'] = strtotime($param['starttime']);
            $model->addData($param);
        } catch (\Exception $e) {
            systembug($e->getMessage(),1,'admin/Actionpopup/add');
            return admin_json(-1, '添加失败' . $e->getMessage());
        }
        return admin_json(1, '添加成功');
    }
    /**
     * [index  ]
     * @return mixed|string
     * @author [C。]
     */
    public function edit()
    {
        $param = input('param.');
        $model = new ActionPopupModel;
        try {
            $model->editData($param);
        } catch (\Exception $e) {
            systembug($e->getMessage(),1,'admin/Actionpopup/edit');
            return admin_json(-1, '编辑失败' . $e->getMessage());
        }
        return admin_json(1, '编辑成功');
    }
    /**
     * [index  ]
     * @return mixed|string
     * @author [C。]
     */
    public function del()
    {
        $param = input('param.');
        $model = new ActionPopupModel;
        try {
            $param['status'] = 2;
            $model->editData($param);
        } catch (\Exception $e) {
            systembug($e->getMessage(),1,'admin/Actionpopup/del');
            return admin_json(-1, '关闭失败' . $e->getMessage());
        }
        return admin_json(1, '关闭成功');
    }
}